/**
 * 
 */
package com.iknight.mgr.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iknight.mgr.api.PubCodeService;
import com.iknight.mgr.mapper.PubCodeMapper;
import com.iknight.mgr.model.CodeModel;

/**
 * @author Administrator
 *
 */
@Service
public class PubCodeServiceImpl implements PubCodeService<CodeModel, String> {
	@Autowired
	private PubCodeMapper<CodeModel, String> pubCodeMapper;

	
	public void save(CodeModel record) {
		// TODO Auto-generated method stub
		if (pubCodeMapper.selectOne(record.getCode_id()) != null) {
			pubCodeMapper.update(record);
		} else {
			pubCodeMapper.insert(record);
		}
	}

	
	public void delete(String pkey) {
		// TODO Auto-generated method stub
		pubCodeMapper.delete(pkey);
	}

	
	public CodeModel selectOne(String pkey) {
		// TODO Auto-generated method stub
		return pubCodeMapper.selectOne(pkey);
	}

	
	public PageInfo<CodeModel> selectPage(Map<String, Object> params, int pageStart, int pageSize) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageStart, pageSize, true);
		List<CodeModel> codeList = pubCodeMapper.selectByCond(params);
		PageInfo<CodeModel> page = new PageInfo<CodeModel>(codeList);
		return page;
	}

	
	public void changeCodePid(String code_id, String p_code_id) {
		// TODO Auto-generated method stub
		pubCodeMapper.changeCodePid(code_id, p_code_id);
	}

	@SuppressWarnings("rawtypes")
	
	public List<Map> getAllCode() {
		// TODO Auto-generated method stub
		return pubCodeMapper.getAllCode();
	}

	
	public List<Map> getPubCodeByPId(String pid) {
		// TODO Auto-generated method stub
		List<Map> map = pubCodeMapper.getPubCodeByPId(pid);
		return map;
	}

	
	public List<Map> getOptionsByPId(String p_code_id) {
		return pubCodeMapper.getOptionsByPId(p_code_id);
	}

	
	public List<Map> getTreeNode(String nodeId) {
		return pubCodeMapper.getTreeNode(nodeId);
	}

	@Override
	public List<Map> getOptionsByCode(String code_name) {
		return pubCodeMapper.getOptionsByPCode(code_name);
	}
}
